Skip to content

🛡️ Sentinel: [CRITICAL] Fix Auth Bypass - Enforce Invite Code Validation - #411

Open
criptogus wants to merge 1 commit into
mainfrom
sentinel-auth-invite-bypass-fix-6239222094704057239
Open

🛡️ Sentinel: [CRITICAL] Fix Auth Bypass - Enforce Invite Code Validation#411
criptogus wants to merge 1 commit into
mainfrom
sentinel-auth-invite-bypass-fix-6239222094704057239

Conversation

@criptogus

Copy link
Copy Markdown
Owner

Vulnerability Fixed:
The POST /api/auth/register endpoint accepted an inviteCode but did not validate it, allowing any user to register even if the system was intended to be Invite-Only (as suggested by the frontend "Waiting List" redirection).

Resolution:

  1. Mandatory Validation: The endpoint now checks for the presence and validity of inviteCode against the invitation_codes table.
  2. Transaction Safety: User creation and invite usage increment are now atomic within a database transaction.
  3. Regression Testing: Added a comprehensive test suite backend/src/tests/routes/auth-invite.test.ts verifying:
    • Missing code -> 400 Bad Request
    • Invalid code -> 400 Bad Request
    • Expired code -> 400 Bad Request
    • Exhausted code -> 400 Bad Request
    • Valid code -> 201 Created (and increments usage)

Learnings Recorded:
Updated .Jules/sentinel.md with findings regarding backend enforcement vs frontend obscurity.


PR created automatically by Jules for task 6239222094704057239 started by @criptogus

- Modified `POST /api/auth/register` to require `inviteCode`.
- Added validation logic against `invitation_codes` table (existence, expiry, max uses).
- Wrapped user creation and invite usage increment in a database transaction for data integrity.
- Added regression test `backend/src/tests/routes/auth-invite.test.ts` to verify the fix and prevent regression.

This fixes a critical vulnerability where the registration endpoint allowed bypassing the invite-only restriction.

Co-authored-by: criptogus <128640021+criptogus@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31c445a1ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +93 to +94
// Increment invitation usage
await client.query('UPDATE invitation_codes SET current_uses = current_uses + 1 WHERE id = $1', [invitation.id]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce invite usage limit atomically

The invite limit is validated before the transaction and the update here is unconditional, so two concurrent registrations can both pass the pre-check and then increment current_uses, allowing more users than max_uses. This shows up when an invite has only one remaining use (or is at its limit) and two requests arrive close together. Consider moving the invite lookup into the same transaction with SELECT ... FOR UPDATE, or make this UPDATE conditional on current_uses < max_uses and check the affected row count before completing registration.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant